//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//********************************************************* 

using System;
using System.Collections.ObjectModel;

namespace Microsoft.TridentWordAddIn.Common
{
    /// <summary>
    /// The controller of the Trident Package
    /// </summary>
    public interface IController
    {
        /// <summary>
        /// Occurs when [on connection changed].
        /// </summary>
        event EventHandler<ConnectionChangedEventArgs> OnConnectionChanged;

        /// <summary>
        /// Occurs when [on picture selection changed].
        /// </summary>
        event EventHandler<PictureSelectionChangedEventArgs> OnPictureSelectionChanged;

        /// <summary>
        /// Occurs when [on association changed].
        /// </summary>
        event EventHandler<AssociationChangedEventArgs> OnAssociationChanged;

        /// <summary>
        /// Occurs when [on association progress].
        /// </summary>
        event EventHandler<ProgressEventArgs> AssociationProgress;

        /// <summary>
        /// Occurs when [on rerun completed].
        /// </summary>
        event EventHandler<RerunCompletedEventArgs> OnRerunCompleted;

        /// <summary>
        /// Occurs when [on rerun clicked].
        /// </summary>
        event EventHandler<SelectedAssociationEventArgs> OnRerunClicked;

        /// <summary>
        /// Occurs when [on document closing].
        /// </summary>
        event EventHandler<BaseEventArgs> OnDocumentClosing;

        /// <summary>
        /// Gets the trident server.
        /// </summary>
        /// <value>The trident server.</value>
        ITridentServer Server { get; }

        /// <summary>
        /// Gets or sets the data store.
        /// </summary>
        /// <value>The data store.</value>
        IDataStore DataStore { get; set; }

        /// <summary>
        /// Gets the server broker.
        /// </summary>
        /// <value>The server broker.</value>
        IServerBroker ServerBroker { get; }

        /// <summary>
        /// Gets the documents count.
        /// </summary>
        /// <value>The documents count.</value>
        int DocumentsCount { get; }

        /// <summary>
        /// Gets the current document key.
        /// </summary>
        /// <value>The current document key.</value>
        int CurrentDocumentKey { get; }

        /// <summary>
        /// Gets or sets the active connection for document.
        /// </summary>
        /// <value>The active connection for document.</value>
        string CurrentConnectionName { get; set; }

        /// <summary>
        /// Gets the user data.
        /// </summary>
        /// <value>The user data.</value>
        UserData UserData { get; }

        /// <summary>
        /// Gets or sets the current connection.
        /// </summary>
        /// <value>The current connection.</value>
        TridentConnection CurrentConnection { get; set; }

        /// <summary>
        /// Gets or sets the selected picture.
        /// </summary>
        /// <value>The selected picture.</value>
        DocumentPicture SelectedPicture { get; set; }

        /// <summary>
        /// Gets the range.
        /// </summary>
        /// <value>The range.</value>
        PictureRange Range { get; }

        /// <summary>
        /// Sets the package host.
        /// </summary>
        /// <param name="taskPaneManager">The task pane manager.</param>
        void InitializeBaseTaskPaneManager(ITaskPaneManager taskPaneManager);

        /// <summary>
        /// Sets the package host.
        /// </summary>
        /// <param name="ribbonInvalidator">The ribbon invalidator.</param>
        void InitializeBaseRibbonInvalidator(IRibbonInvalidator ribbonInvalidator);

        /// <summary>
        /// Sets the package host.
        /// </summary>
        /// <param name="packageHost">The package host.</param>
        void SetPackageHost(IThisAddInPackageHost packageHost);

        /// <summary>
        /// Shows the server connection form.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="isTempConnection">if set to <c>true</c> [is temp connection].</param>
        /// <returns>bool</returns>
        bool ShowServerConnectionForm(ref TridentConnection connection, bool isTempConnection);

        /// <summary>
        /// Shows the Trident server connection form.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="editMode">if set to <c>true</c> [edit mode].</param>
        /// <param name="deleteOnCancel">if set to <c>true</c> [delete on cancel].</param>
        /// <returns>bool</returns>
        bool ShowServerConnectionForm(ref TridentConnection connection, bool editMode, bool deleteOnCancel);

        /// <summary>
        /// Gets the connectio name by document key.
        /// </summary>
        /// <param name="documentKey">The document key.</param>
        /// <returns>string</returns>
        string GetConnectionByDocumentKey(int documentKey);

        /// <summary>
        /// Gets the model by document key.
        /// </summary>
        /// <param name="documentKey">The document key.</param>
        /// <returns>Model</returns>
        Model GetModelByDocumentKey(int documentKey);

        /// <summary>
        /// Sets the connection name by document key.
        /// </summary>
        /// <param name="documentKey">The document key.</param>
        /// <param name="connectionName">Name of the connection.</param>
        void SetConnectionByDocumentKey(int documentKey, string connectionName);

        /// <summary>
        /// Removes the connection.
        /// </summary>
        /// <param name="connectionName">Name of the connection.</param>
        /// <returns>bool</returns>
        bool RemoveConnection(string connectionName);

        /// <summary>
        /// Documents the protection.
        /// </summary>
        void DocumentProtection();

        /// <summary>
        /// Shows the task pane.
        /// </summary>
        /// <param name="taskPaneKey">The task pane key.</param>
        /// <param name="isPressed">if set to <c>true</c> [is pressed].</param>
        void ShowTaskPane(TaskPaneKey taskPaneKey, bool isPressed);

        /// <summary>
        /// Determines whether [is task pane visible] [the specified control id].
        /// </summary>
        /// <param name="controlId">The control id.</param>
        /// <returns>
        /// 	<c>true</c> if [is task pane visible] [the specified control id]; otherwise, <c>false</c>.
        /// </returns>
        bool IsTaskPaneVisible(string controlId);

        /// <summary>
        /// Reruns the workflow.
        /// </summary>
        /// <param name="server">The server.</param>
        /// <param name="rerunWorkflowParam">The rerun workflow param.</param>
        /// <returns>Guid</returns>
        Guid SumbitJob(ITridentServer server, RerunWorkflowInformation rerunWorkflowParam);

        /// <summary>
        /// Associates the workflow.
        /// </summary>
        /// <param name="documentKey">The document key.</param>
        /// <param name="workflow">The workflow.</param>
        /// <param name="association">The association.</param>
        /// <param name="server">The server.</param>
        void AssociateWorkflow(int documentKey, Workflow workflow, WorkflowAssociation association, ITridentServer server);

        /// <summary>
        /// Determines whether this instance [can workflow associate] the specified is linked.
        /// </summary>
        /// <param name="documentKey">The document key.</param>
        /// <returns>
        /// 	<c>true</c> if this instance [can workflow associate] the specified is linked; otherwise, <c>false</c>.
        /// </returns>
        bool CheckDocumentProtection(int documentKey);

        /// <summary>
        /// Gets all workflow associations.
        /// </summary>
        /// <param name="documentKey">The document key.</param>
        /// <returns>ReadOnlyCollection of WorkflowAssociation</returns>
        ReadOnlyCollection<WorkflowAssociation> GetAllWorkflowAssociations(int documentKey);

        /// <summary>
        /// Gets all workflow associations.
        /// </summary>
        /// <param name="documentKey">The document key.</param>
        /// <param name="documentPicture">The document picture.</param>
        /// <returns>ReadOnlyCollection of WorkflowAssociation</returns>
        ReadOnlyCollection<WorkflowAssociation> GetAllWorkflowAssociations(int documentKey, DocumentPicture documentPicture);

        /// <summary>
        /// Exports the package.
        /// </summary>
        /// <param name="documentKey">The document key.</param>
        /// <param name="filePath">The file path.</param>
        /// <param name="activityId">The activity id.</param>
        /// <param name="server">The server.</param>
        void ExportPackage(int documentKey, string filePath, Guid activityId, ITridentServer server);

        /// <summary>
        /// Begins the model transaction.
        /// </summary>
        /// <param name="documentKey">The document key.</param>
        void BeginModelTransaction(int documentKey);

        /// <summary>
        /// Commits the model transaction.
        /// </summary>
        /// <param name="documentKey">The document key.</param>
        void CommitModelTransaction(int documentKey);

        /// <summary>
        /// Rollbacks the model transaction.
        /// </summary>
        /// <param name="documentKey">The document key.</param>
        void RollbackModelTransaction(int documentKey);

        /// <summary>
        /// Determines whether [is transaction active] [the specified document key].
        /// </summary>
        /// <param name="documentKey">The document key.</param>
        /// <returns>
        /// 	<c>true</c> if [is transaction active] [the specified document key]; otherwise, <c>false</c>.
        /// </returns>
        bool IsTransactionActive(int documentKey);

        /// <summary>
        /// Deletes the workflow association.
        /// </summary>
        /// <param name="documentKey">The document key.</param>
        /// <param name="associationId">The association id.</param>
        void DeleteWorkflowAssociation(int documentKey, int associationId);

        /// <summary>
        /// Connections the changed.
        /// </summary>
        /// <param name="isCurrentConnection">if set to <c>true</c> [is current connection].</param>
        /// <param name="operation">The operation.</param>
        void ConnectionChanged(bool isCurrentConnection, ConnectionOperation operation);

        /// <summary>
        /// Associations the changed.
        /// </summary>
        /// <param name="documentKey">The document key.</param>
        /// <param name="picture">The picture.</param>
        void AssociationChanged(int documentKey, DocumentPicture picture);

        /// <summary>
        /// Reruns the clicked.
        /// </summary>
        /// <param name="documentKey">The document key.</param>
        /// <param name="association">The association.</param>
        void RerunClicked(int documentKey, WorkflowAssociation association);

        /// <summary>
        /// Workflows the by id.
        /// </summary>
        /// <param name="documentKey">The document key.</param>
        /// <param name="workflowId">The workflow id.</param>
        /// <returns>Workflow</returns>
        Workflow WorkflowById(int documentKey, Guid workflowId);

        /// <summary>
        /// Inserts the trident link.
        /// </summary>
        /// <param name="documentKey">The document key.</param>
        /// <param name="range">The range.</param>
        /// <param name="association">The association.</param>
        void InsertTridentLink(int documentKey, PictureRange range, WorkflowAssociation association);

        /// <summary>
        /// Tests the connection and prompt if required.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="connectionReturn">The connection which is returned after user provided credential</param>
        /// <param name="deleteOnCancel">if true the ConnectionForm will ask confirmation when user choose cancel or close for removing the connection</param>
        /// <returns>bool</returns>
        bool TestConnectionAndPromptIfRequired(TridentConnection connection, ref TridentConnection connectionReturn, bool deleteOnCancel);

        /// <summary>
        /// Sets the next default connection.
        /// </summary>
        void SetNextDefaultConnection();

        /// <summary>
        /// Reruns the completed.
        /// </summary>
        /// <param name="documentKey">The document key.</param>
        /// <param name="association">The association.</param>
        void RerunCompleted(int documentKey, WorkflowAssociation association);

        /// <summary>
        /// Adds the appendix entry.
        /// </summary>
        /// <param name="insertIntoDocumentData">The insert into document data.</param>
        void AddAppendixEntry(AppendixResult insertIntoDocumentData);

        /// <summary>
        /// Determines whether [is connection present].
        /// </summary>
        /// <returns>
        /// 	<c>true</c> if [is connection present]; otherwise, <c>false</c>.
        /// </returns>
        bool IsConnectionPresent();

        /// <summary>
        /// Determines whether [is associations present].
        /// </summary>
        /// <returns>
        /// 	<c>true</c> if [is associations present]; otherwise, <c>false</c>.
        /// </returns>
        bool IsAssociationsPresent();
             
        /// <summary>
        /// Determines whether [is connection and association present].
        /// </summary>
        /// <returns>
        /// 	<c>true</c> if [is connection and association present]; otherwise, <c>false</c>.
        /// </returns>
        bool IsConnectionAndAssociationsPresent();
        
        /// <summary>
        /// Selects the picture by document.
        /// </summary>
        /// <param name="documentKey">The document key.</param>
        /// <param name="pictureKey">The picture key.</param>
        void SelectPictureByDocument(int documentKey, string pictureKey);
    }
}
